package com.qian.service.ddj.entity;

import com.qian.api.ddj.model.PayTypeDict;
import com.yaowk.service.common.BaseEntity;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.util.ObjectUtils;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Set;

@Getter
@Setter
@ToString
@Entity
@DynamicInsert
@DynamicUpdate
public class DdjBusinessGroup extends BaseEntity<Integer> {

    private String name;
    @Column(nullable = false)
    private BigDecimal d0;
    @Column(nullable = false)
    private BigDecimal t0;
    @Column(nullable = false)
    private BigDecimal d1;
    @Column(nullable = false)
    private BigDecimal t1;
    @ColumnDefault("0")
    private Integer lazyTime; // 延迟时间  只对t1有效 单位小时
    @ColumnDefault("0")
    private Integer settlementTime; // 结算时间
    @ColumnDefault("0")
    @Column(nullable = false)
    private Byte allowAliWap; // 允许支付宝wap
    @ColumnDefault("0")
    @Column(nullable = false)
    private BigDecimal tariffAliWap; // 支付宝wap费率
    @ColumnDefault("0")
    @Column(nullable = false)
    private Byte allowAliCode; // 允许支付宝扫码
    @ColumnDefault("0")
    @Column(nullable = false)
    private BigDecimal tariffAliCode; // 支付宝扫码费率
    @ColumnDefault("0")
    @Column(nullable = false)
    private Byte allowWxH5; // 允许微信h5
    @ColumnDefault("0")
    @Column(nullable = false)
    private BigDecimal tariffWxH5;
    @ColumnDefault("0")
    @Column(nullable = false)
    private Byte allowWxCode; // 允许微信扫码
    @ColumnDefault("0")
    @Column(nullable = false)
    private BigDecimal tariffWxCode;
    @ColumnDefault("0")
    @Column(nullable = false)
    private Byte allowCodeBank; // 允许银联扫码支付
    @ColumnDefault("0")
    @Column(nullable = false)
    private BigDecimal tariffCodeBank;
    @ColumnDefault("0")
    @Column(nullable = false)
    private Byte allowQuickBank; // 允许银行快捷支付
    @ColumnDefault("0")
    @Column(nullable = false)
    private BigDecimal tariffQuickBank;
    @ColumnDefault("0")
    @Column(nullable = false)
    private Byte allowQq; // 允许qq支付
    @ColumnDefault("0")
    @Column(nullable = false)
    private BigDecimal tariffQq;
    @ColumnDefault("0")
    @Column(nullable = false)
    private Byte allowQqWap; // 允许qqwap支付
    @ColumnDefault("0")
    @Column(nullable = false)
    private BigDecimal tariffQqWap;
    @ColumnDefault("0")
    @Column(nullable = false)
    private Byte allowJd; // 允许京东支付
    @ColumnDefault("0")
    @Column(nullable = false)
    private BigDecimal tariffJd;
    @ColumnDefault("0")
    @Column(nullable = false)
    private BigDecimal minCashFee; // 最低提现手续费
    @ColumnDefault("0")
    @Column(nullable = false)
    private BigDecimal cashPercent; // 提现手续费百分百部分
    @ColumnDefault("0")
    @Column(nullable = false)
    private BigDecimal cashFixed; // 提现手续费固定部分
    @ColumnDefault("100")
    @Column(nullable = false)
    private BigDecimal minCashMoney; // 最低提现金额
    @Column(updatable = false, insertable = false)
    private Integer channelId;

    private String backup1; // 备用字段
    private String backup2;
    private String backup3;
    private String backup4;
    private String backup5;

    @OneToMany(mappedBy = "businessGroup")
    private Set<DdjBusiness> businesses;

    @ManyToOne
    @JoinColumn(name = "channelId")
    private DdjChannel channel;

    @OneToMany
    @JoinColumn(name = "groupId")
    private Set<DdjMoneyMap> moneyMaps;


    /**
     * 计算费率
     *
     * @param payType
     * @return
     */
    public BigDecimal tariff(Byte payType) {
        BigDecimal tariff = null;
        if (payType.equals(PayTypeDict.ALI_CODE)) {
            tariff = getTariffAliCode();
        } else if (payType.equals(PayTypeDict.WX_CODE)) {
            tariff = getTariffWxCode();
        } else if (payType.equals(PayTypeDict.ALI_WAP)) {
            tariff = getTariffAliWap();
        } else if (payType.equals(PayTypeDict.WX_H5)) {
            tariff = getTariffWxH5();
        } else if (payType.equals(PayTypeDict.QUICK_BANK)) {
            tariff = getTariffQuickBank();
        } else if (payType.equals(PayTypeDict.QQ)) {
            tariff = getTariffQq();
        } else if (payType.equals(PayTypeDict.JD)) {
            tariff = getTariffJd();
        } else if (payType.equals(PayTypeDict.QQ_WAP)) {
            tariff = getTariffQqWap();
        } else if (payType.equals(PayTypeDict.CODE_BANK)) {
            tariff = getTariffCodeBank();
        }
        if (ObjectUtils.isEmpty(tariff)) {
            throw new RuntimeException("费率错误");
        }
        return tariff;
    }
}
